package com.ithemai.work;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @auther Macrydy
 * @date 2020/7/4 18:04
 * 题目四
 * 		请按以下要求编写程序：
 * 		1).定义一个学员类，有以下属性：姓名、性别、年龄、分数
 * 		  无参、全参构造方法，get/set方法
 * 		2).定义main()方法，定义一个存储Student的集合，并初始化一些数据：
 * 			List<Student> stuList = new ArrayList<>();
 * 			stuList.add(new Student(“迪丽热巴”,”女”,18,99);
 * 			stuList.add(new Student(“古力娜扎”,”女”,19,98);
 * 			stuList.add(new Student(“周杰伦”,”男”,20,88);
 * 			stuList.add(new Student(“蔡徐坤”,”男”,19,78);
 * 			/*
 * 			定义一个字符缓冲输出流BufferedWriter，将学员信息写入到”test3_4.txt”中，
 *             每个学员信息占一行，每个字段之间用,符号隔开，例如：
 * 				迪丽热巴,女,18,99
 * 				古力娜扎,女,19,98
 * 				周杰伦,男,20,88
 * 				蔡徐坤,男,19,78
 */
public class Test4 {
    public static void main(String[] args)throws IOException {
        List<Student> stuList = new ArrayList<>();
  			stuList.add(new Student("迪丽热巴","女",18,99));
  			stuList.add(new Student("古力娜扎","女",19,98));
  			stuList.add(new Student("周杰伦","男",20,88));
  			stuList.add(new Student("蔡徐坤","男",19,78));

        BufferedWriter bw = new BufferedWriter(new FileWriter("test3_4.txt"));


        for (int i = 0; i < stuList.size(); i++) {
            StringBuilder sb = new StringBuilder();
            sb.append(stuList.get(i).getName()).append(",")
                    .append(stuList.get(i).getSex()).append(",")
                    .append(stuList.get(i).getAge()).append(",")
                    .append(stuList.get(i).getScore());
            bw.write(sb.toString());
            bw.newLine();
            bw.flush();
        }

        bw.close();
    }
}
class Student{
    //定义一个学员类，有以下属性：姓名、性别、年龄、分数
    private String name;
    private String sex;
    private int age;
    private int score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public Student(String name, String sex, int age, int score) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.score = score;
    }

    public Student() {
    }
}